﻿package com.mrent.service;

public class Page {
	
	
	private int pageSize=10;
	
	private int pageNo=1;
	
	private int totalCount;
	
	private int totalPage;

	private int start;

	private int end;
	
	public Page(){
		this.pageSize = 10; //默认每页10条记录
		this.pageNo = 1; //默认第一页
	    this.totalCount = 0; //共多少条记录
	}
	
	public Page(final int pageSize){
		setPageSize(pageSize);
	}
	
	
	public int getFirst(){
		return ((pageNo-1)*pageSize);
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
		if(pageSize<1){
			this.pageSize=1;
		}
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
		if(pageNo<1){
			this.pageNo=1;
		}
	}
	
	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}
	
	/**
	 * 是否还有下一页.
	 */
	public boolean isHasNext() {
		return (pageNo + 1 <= getTotalPage());
	}
	
	
	/**
	 * 是否还有上一页.
	 */
	public boolean isHasPre() {
		return (pageNo - 1 >= 1);
	}

	public int getTotalPage() {
		if (totalCount < 0)
			return -1;

		int count = totalCount / pageSize;
		if (totalCount % pageSize > 0) {
			count++;
		}
		return count;
	}
	
	

}
